package com.service.component.permissions.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.service.component.common.CommonResult;
import com.service.component.common.utils.CommonUtils;
import com.service.component.permissions.entity.Permission;
import com.service.component.permissions.mapper.PermissionMapper;
import com.service.component.permissions.services.PermissionService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Calvin
 * @create ：2021/7/22 13:19
 * @description：权限服务的实现
 * @modified By：
 * @version: 1.0.0$
 */
@Service
public class PermissionServicesImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public CommonResult insertPermission(Permission permission) {
        int insert = permissionMapper.insert(permission);
        return insert > 0 ? CommonResult.success() : CommonResult.commonResult(CommonResult.ResultCode.REQUEST_SQL_ERROR);
    }

    @Override
    public List<Permission> getPermissionByUserId(String userId) {
        return permissionMapper.getPermissionByUserId(userId);
    }

    @Override
    public Permission getPermissionByPermName(String permName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PERM_NAME_EN",permName);
        return permissionMapper.selectOne(queryWrapper);
    }
}
